package com.king.single;

import java.lang.reflect.Constructor;

public enum EnumSingle {

    INSTANCE;

    public EnumSingle getInstance(){
        return INSTANCE;
    }
}
class test{
    public static void main(String[] args) throws Exception {
        EnumSingle instance1 = EnumSingle.INSTANCE;
        //EnumSingle instance2 = EnumSingle.INSTANCE;

       /* Constructor<EnumSingle> declaredConstructor = EnumSingle.class.getDeclaredConstructor(null);
        declaredConstructor.setAccessible(true);
        EnumSingle enumSingle = declaredConstructor.newInstance();*/

        //NoSuchMethodException: com.king.single.EnumSingle.<init>() 没有这个方法
        //System.out.println(instance1==enumSingle);
        Constructor<EnumSingle> declaredConstructor1 = EnumSingle.class.getDeclaredConstructor(String.class,int.class);
        declaredConstructor1.setAccessible(true);
        EnumSingle enumSingle1 = declaredConstructor1.newInstance();

        //Exception in thread "main" java.lang.IllegalArgumentException: Cannot reflectively create enum objects 不能通过反射
        System.out.println(instance1==enumSingle1);

    }
}